import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 高生平
 * Date: 2025-11-03
 * Time: 18:40
 */

//实现一个简单的控制台版用户登陆程序, 程序启动提示用户输入用户名密码. 如果用户名密码出错, 使用自定义异常的方式来处理

public class Test {
    private String userName = "Tom";
    private String passWord = "123456";

    public void logIn(String userName, String passWord) throws PassWordException,UserNameException{
        if (!(this.userName.equals(userName))) {
            throw new UserNameException("用户名异常");
        }
        if (!(this.passWord.equals(passWord))) {
            throw new PassWordException("密码异常");
        }
        System.out.println("登录成功");
    }

    public static void main(String[] args) {
        Test test = new Test();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String userName = scanner.nextLine();
        System.out.println("请输入密码：");
        String passWord = scanner.nextLine();
        try{
            test.logIn(userName, passWord);
        } catch (UserNameException userNameException) {
            userNameException.printStackTrace();
            System.out.println("UserNameException");
        } catch (PassWordException passWordException) {
            passWordException.printStackTrace();
            System.out.println("PassWordException");
        }
    }
}
